package com.xy.condition;

import com.xy.bean.RainBow;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/4/8 16:32
 * @description
 */


public class MyBeanImport implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        boolean contation1 = registry.containsBeanDefinition("com.xy.bean.Red");
        boolean contation2 = registry.containsBeanDefinition("com.xy.bean.Blue");
        if (contation1 && contation2) {
            RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(RainBow.class);
            registry.registerBeanDefinition("rainBow",rootBeanDefinition);
        }

    }
}
